package com.itheima.book.utils;

import lombok.Data;
import java.util.List;

@Data
public class PageHelper<T> {
    /**
     * 总记录数
     */
    private long total;

    /**
     * 当前页数据
     */
    private List<T> list;

    /**
     * 当前页码
     */
    private int currentPage;

    /**
     * 每页显示记录数
     */
    private int pageSize;

    /**
     * 总页数
     */
    private int totalPages;

    public PageHelper() {
    }

    public PageHelper(int currentPage, int pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    public void setTotal(long total) {
        this.total = total;
        this.totalPages = (int) Math.ceil((double) total / pageSize);
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public int getStartIndex() {
        return (currentPage - 1) * pageSize;
    }
} 